using System;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using YB.EnterpriseLibrary.XSLTManager.Configuration.Design.Properties;
using System.ComponentModel;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design.Validation;

namespace YB.EnterpriseLibrary.XSLTManager.Configuration.Design
{
    public class XSLTManagerNode : ConfigurationNode
    {
        private bool debug;
        private bool enableDocumentFunction;
        private bool enableScript;
        private string url;
        private string mimeType;

        public XSLTManagerNode()
			: this(new XSLTManagerData(Resources.DefaultXSLTManagerName))
        {
            
        }

        public XSLTManagerNode(XSLTManagerData xsltManagerData)
            : base((xsltManagerData == null) ? Resources.DefaultXSLTManagerNodeName : xsltManagerData.Name)
        {
            if (xsltManagerData == null) { throw new ArgumentNullException("xsltManagerData"); }
            debug = xsltManagerData.Debug;
            enableDocumentFunction = xsltManagerData.EnableDocumentFunction;
            enableScript = xsltManagerData.EnableScript;
            url = xsltManagerData.Url;
            mimeType = xsltManagerData.MimeType;
        }

        [Required]
        [SRDescription("Debug", typeof(Resources))]
        [SRCategory("CategoryGeneral", typeof(Resources))]
        public bool Debug
        {
            get { return debug; }
            set { debug = value; }
        }

        [Required]
        [SRDescription("URL", typeof(Resources))]
        [SRCategory("CategoryGeneral", typeof(Resources))]
        public string Url
        {
            get { return url; }
            set { url = value; }
        }

        [Required]
        [SRDescription("MimeType", typeof(Resources))]
        [SRCategory("CategoryGeneral", typeof(Resources))]
        public string MimeType
        {
            get { return mimeType; }
            set { mimeType = value; }
        }

        [Required]
        [SRDescription("EnableScript", typeof(Resources))]
        [SRCategory("CategoryGeneral", typeof(Resources))]
        public bool EnableScript
        {
            get { return enableScript; }
            set { enableScript = value; }
        }

        [Required]
        [SRDescription("EnableDocumentFunction", typeof(Resources))]
        [SRCategory("CategoryGeneral", typeof(Resources))]
        public bool EnableDocumentFunction
        {
            get { return enableDocumentFunction; }
            set { enableDocumentFunction = value; }
        }
        
        [Browsable(false)]
        public XSLTManagerData XSLTManagerData
        {
            get
            {
                XSLTManagerData data = new XSLTManagerData(Name);
                data.Debug = debug;
                data.Url = url;
                data.EnableScript = enableScript;
                data.EnableDocumentFunction = enableDocumentFunction;
                data.MimeType = mimeType;
                return data;
            }
        }	
    }
}
